package com.example.loglib.Thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * Created by huangbei on 2017/9/5.
 */

public class SingleThreadPool {

    private ExecutorService executorService ;

    private static SingleThreadPool instance;

    private SingleThreadPool(){
        executorService = Executors.newSingleThreadExecutor();
    }

    public static SingleThreadPool getInstance(){
        if(instance == null){
            synchronized (SingleThreadPool.class){
                if(instance == null){
                    instance = new SingleThreadPool();
                }
            }
        }
        return instance;
    }

    public Future<?> submit(Runnable task) {
        return this.executorService.submit(task);
    }

    public void execute(Runnable task) {
        this.executorService.execute(task);
    }
}
